Skip to content

[Bugfix] Fix JWT Secret Tail characters #1867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ajanikow
Copy link
Collaborator

@ajanikow ajanikow commented Apr 9, 2025

No description provided.

@cla-bot cla-bot bot added the cla-signed label Apr 9, 2025
@ajanikow ajanikow force-pushed the bugfix/fix_secret_discovery branch 2 times, most recently from bc9ded2 to fcdfb59 Compare April 29, 2025 14:55
@ajanikow ajanikow force-pushed the bugfix/fix_secret_discovery branch from fcdfb59 to 693c92c Compare May 14, 2025 11:28
@ajanikow ajanikow force-pushed the bugfix/fix_secret_discovery branch 5 times, most recently from 315ccaa to 0209639 Compare June 3, 2025 08:01
@ajanikow ajanikow force-pushed the bugfix/fix_secret_discovery branch from 701bb68 to c19a0ef Compare July 14, 2025 15:50
@ajanikow ajanikow requested a review from Copilot July 14, 2025 16:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the JWT secret handling to use a fixed-size Secret abstraction, adds trimming/filling of secret byte slices, and replaces direct JWT calls with a unified Secret/Claims API throughout the codebase.

  • Introduce Secret interface and implementations (secret, Secrets, emptySecret, secretSet) with trimming/filling to DefaultTokenSecretSize
  • Update token parsing/signing in pkg/util/token and callers to use Claims.Sign and Secret.Validate
  • Add extensive tests in token_test.go for trimming, filling, and prefix/postfix removal behaviors

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/util/token/token.go New Validate and token type wrapping with fixed-size secrets
pkg/util/token/secret.go Trim/fill logic for secrets, NewSecretWithSize implementation
pkg/util/token/secrets.go Secrets collection type and validation over a set
pkg/util/token/secret_set.go secretSet combining primary and secondary secrets
pkg/util/token/secret_empty.go Empty secret stub
pkg/util/token/mods.go Updated modifiers signature to util.ModR
pkg/util/token/claims.go Claims builder and .Sign method
pkg/util/token/interface.go Introduced Secret and Token interfaces
pkg/util/token/consts.go JWT claim constants
pkg/util/token/method.go Default JWT signing method
pkg/util/token/token_test.go New tests covering trimming, filling, prefix/postfix behavior
pkg/util/mod.go Moved emptyModR and updated ApplyModsR
pkg/util/k8sutil/secrets.go Added GetTokenSecret overloads
Multiple callers (k8sutil, arangod, backup handlers, deployment resources, CLI, integration) Switched to Claims.Sign and Secret.Validate usage
Comments suppressed due to low confidence (1)

pkg/util/token/token_test.go:207

  • [nitpick] The test name "Ensure token gets trimmed" is used twice; consider renaming one of them to clearly distinguish the scenarios.
	t.Run("Ensure token gets trimmed", func(t *testing.T) {

)

type Mod func(in Claims) Claims
func Validate(t string, secret []byte) (Token, error) {
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce the expected signing algorithm in Validate by adding jwt.WithValidMethods(jwt.SigningMethodHS256.Alg()) (or a similar option) to jwt.Parse to avoid accepting tokens signed with none or other algorithms.

Copilot uses AI. Check for mistakes.


return !equality.Semantic.DeepDerivative(tokenClaims, exporterTokenClaims), true, nil
return !equality.Semantic.DeepDerivative(tokenClaims, expectedClaims), true, nil
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the actual claims map, not the Token interface, to DeepDerivative. For example:
return !equality.Semantic.DeepDerivative(tokenClaims.Claims(), expectedClaims), true, nil

Suggested change
return !equality.Semantic.DeepDerivative(tokenClaims, expectedClaims), true, nil
return !equality.Semantic.DeepDerivative(tokenClaims.Claims(), expectedClaims), true, nil

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants